{smcl}
{com}{sf}{ul off}{txt}{.-}
      name:  {res}<unnamed>
       {txt}log:  {res}C:\Users\myogo\Princeton Dropbox\Motohiro Yogo\Koijen Yogo - International\JPE\Replication\Code\1 Data\Ratings.smcl
  {txt}log type:  {res}smcl
 {txt}opened on:  {res} 7 Nov 2025, 15:02:22
{txt}
{com}. /* Define local and global variables */
> 
> local directory = "../../Data_nonpublic/Compustat";
{txt}
{com}. do global;
{txt}
{com}. /* global.do (STATA)
>         Define global variables in "Data".
>         by Ralph Koijen & Motohiro Yogo */
. 
. #delimit ;
{txt}delimiter now ;
{com}. clear all;
{res}{txt}
{com}. global year_min = 2003;
{txt}
{com}. global year_max = 2020;
{txt}
{com}. global small = 5e-4;
{txt}
{com}.         /* Minimum reportable threshold for CPIS */

{txt}end of do-file

{com}. /* Step 1: Prepare default rates */
> 
> /* Load data */
> 
> u "`directory'/SP Default Rates" if years==10, clear;
{txt}
{com}. drop years;
{txt}
{com}. /* Construct log variables */
> 
> gen Ldefault = ln(default);
{txt}(6 missing values generated)

{com}. /* Fit an exponential curve */
> 
> reg Ldefault order, robust;

{txt}Linear regression                               Number of obs     = {res}        14
                                                {txt}F(1, 12)          =  {res}     9.02
                                                {txt}Prob > F          = {res}    0.0110
                                                {txt}R-squared         = {res}    0.4904
                                                {txt}Root MSE          =    {res} .87579

{txt}{hline 13}{c TT}{hline 11}{hline 11}{hline 9}{hline 8}{hline 13}{hline 12}
{col 14}{c |}{col 26}    Robust
{col 1}    Ldefault{col 14}{c |} Coefficient{col 26}  std. err.{col 38}      t{col 46}   P>|t|{col 54}     [95% con{col 67}f. interval]
{hline 13}{c +}{hline 11}{hline 11}{hline 9}{hline 8}{hline 13}{hline 12}
{space 7}order {c |}{col 14}{res}{space 2} .1819973{col 26}{space 2} .0605961{col 37}{space 1}    3.00{col 46}{space 3}0.011{col 54}{space 4} .0499698{col 67}{space 3} .3140249
{txt}{space 7}_cons {c |}{col 14}{res}{space 2}-4.833963{col 26}{space 2} .9115582{col 37}{space 1}   -5.30{col 46}{space 3}0.000{col 54}{space 4}-6.820078{col 67}{space 3}-2.847848
{txt}{hline 13}{c BT}{hline 11}{hline 11}{hline 9}{hline 8}{hline 13}{hline 12}
{res}{txt}
{com}. predict Ldefault_pred, xb;
{txt}
{com}. drop Ldefault;
{txt}
{com}. /* Construct fitted default rates */
> 
> gen drate = default if order<=4;
{txt}(16 missing values generated)

{com}. replace drate = -exp(Ldefault_pred) if order>4;
{txt}(16 real changes made)

{com}. drop order default Ldefault_pred;
{txt}
{com}. /* Save data */
> 
> tempfile default;
{txt}
{com}. save `default';
{txt}{p 0 4 2}
file {bf}
C:\Users\myogo\AppData\Local\Temp\ST_8970_000001.tmp{rm}
saved
as .dta format
{p_end}

{com}. /* Step 2: Prepare countries */
> 
> u country company_id if !missing(company_id)
>         using Countries, clear;
{txt}
{com}. /* Save data */
> 
> tempfile Countries;
{txt}
{com}. save `Countries';
{txt}{p 0 4 2}
file {bf}
C:\Users\myogo\AppData\Local\Temp\ST_8970_000002.tmp{rm}
saved
as .dta format
{p_end}

{com}. /* Step 3: Construct Capital IQ Ratings data */
> 
> /* Load data */
> 
> u company_id ratingdate ratingtypecode ratingsymbol
>         if ratingtypecode=="STDLONG"
>         using "`directory'/Capital IQ Entity Ratings", clear;
{txt}
{com}. duplicates drop;

{p 0 4}{txt}Duplicates in terms of {txt} all variables{p_end}

(0 observations are duplicates)

{com}. drop ratingtypecode;
{txt}
{com}. /* Merge country code */
> 
> merge m:1 company_id using `Countries',
>         nogen keep(match);
{res}
{txt}{col 5}Result{col 33}Number of obs
{col 5}{hline 41}
{col 5}Not matched{col 30}{res}               0
{txt}{col 5}Matched{col 30}{res}             328{txt}  
{col 5}{hline 41}

{com}. drop company_id;
{txt}
{com}. /* Rename variables */
> 
> rename ratingsymbol rating;
{res}{txt}
{com}. /* Merge default rates */
> 
> merge m:1 rating using `default',
>         nogen keep(match);
{res}
{txt}{col 5}Result{col 33}Number of obs
{col 5}{hline 41}
{col 5}Not matched{col 30}{res}               0
{txt}{col 5}Matched{col 30}{res}             326{txt}  
{col 5}{hline 41}

{com}. /* Construct variables */
> 
> gen int year = year(ratingdate);
{txt}
{com}. gen IratingM = regexm(rating,"^A(\+|-)?$") | regexm(rating,"^BBB(\+|-)?$");
{txt}
{com}. gen IratingJ = regexm(rating,"^BB(\+|-)?$") | regexm(rating,"^B(\+|-)?$") | regexm(rating,"^CC?C?(\+|-)?$");
{txt}
{com}. /* Keep year-end data */
> 
> sort country year ratingdate;
{txt}
{com}. by country year: keep if _n==_N;
{txt}(50 observations deleted)

{com}. /* Expand to annual data */
> 
> by country: gen byte obs = min(year[_n+1],`=$year_max+1')-year;
{txt}
{com}. expand obs, gen(duplicate);
{txt}(3 zero counts ignored; observations not deleted)
(955 observations created)

{com}. bysort country year duplicate: replace year = year+_n if duplicate;
{txt}(955 real changes made)

{com}. drop obs duplicate;
{txt}
{com}. /* Sample criteria */
> 
> keep if inrange(year,$year_min,$year_max);
{txt}(390 observations deleted)

{com}. /* Label variables */
> 
> order year country;
{txt}
{com}. label var year          "Year";
{txt}
{com}. label var rating        "Rating";
{txt}
{com}. label var drate         "Minus 10-year cumulative average default rate";
{txt}
{com}. label var IratingM      "Dummy: Medium grade";
{txt}
{com}. label var IratingJ      "Dummy: Below investment grade";
{txt}
{com}. /* Save data */
> 
> compress;
  {txt}variable {bf}{res}IratingM{sf}{txt} was {bf}{res}double{sf}{txt} now {bf}{res}byte{sf}
  {txt}variable {bf}{res}IratingJ{sf}{txt} was {bf}{res}double{sf}{txt} now {bf}{res}byte{sf}
{txt}  (11,774 bytes saved)

{com}. sort year country;
{txt}
{com}. save Ratings, replace;
{txt}{p 0 4 2}
file {bf}
Ratings.dta{rm}
saved
{p_end}

{com}. log close;
      {txt}name:  {res}<unnamed>
       {txt}log:  {res}C:\Users\myogo\Princeton Dropbox\Motohiro Yogo\Koijen Yogo - International\JPE\Replication\Code\1 Data\Ratings.smcl
  {txt}log type:  {res}smcl
 {txt}closed on:  {res} 7 Nov 2025, 15:02:25
{txt}{.-}
{smcl}
{txt}{sf}{ul off}